package com.example.easyscript.enums;

public class EnumUtils {

    public static <T extends CodeEnum> T getEnumByCode(int code, Class<T> enumClass) {
        for (T each : enumClass.getEnumConstants()) {
            if (each.getCode().equals(code)) {
                return each;
            }
        }
        throw new RuntimeException("找不到对应枚举");
    }

    interface CodeEnum {
        Integer getCode();

        String getType();
    }

}
